
//PLAYERUTILS.JS
//a few utilities for playing songs
// Author: Wilco

function PlayPlaylist(guid,startIndex)
{
	//TODO: make this POST
	var action = 'playMediaList';
		
	var url = ServiceDir + 'player?action=' + action + '&guid=' + guid;
	if (startIndex)
		url = url + '&startIndex=' + startIndex;
	
	$.ajax(
		{
			url: url,
			type: 'POST',
			data: { 'action': action, 'guid': guid, 'startIndex': startIndex},
			error: function(t) 
			{ 
				showError('Error playing media: ' + t.responseText); 
			},
			success: function(response) 
			{
				window.setTimeout("GoToPage('nowplaying');",500);
			}
		});
	
	return false;
}
	

function PlayList(trackList,startIndex)
{
	//TODO: make this POST
	var action = 'playCustomList';
	
	var url = ServiceDir + 'player?action=' + action;
	var guidList = '';
	for(var i=0;i<trackList.length;i++)
		guidList = guidList + "," + trackList[i].guid;
	
	if (guidList == '')
		return;
	else
		guidList = guidList.substring(1);
	
	url = url;
	if (DEBUG) console.log(url);
	
	$.ajax(
		{
			url: url,
			type: 'POST',
			data: { 'action': action, 'guidList': guidList, 'startIndex': startIndex},
			error: function(t) 
			{ 
				showError('Error playing media: ' + t.responseText); 
			},
			success: function(t) 
			{
				setTimeout("GoToPage('nowplaying');",200);
			}
		});
	
	return false;
}
